<%@ page language="java" import="java.util.*, cn.boho.framework.core.*,cn.boho.framework.actions.*,cn.boho.framework.validator.validators.*" pageEncoding="utf8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>"/>
    
    <title>测试的辅助页</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
	<meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/>
	<meta http-equiv="description" content="This is my page"/>
	
	<style type="text/css">
<!--
.aaa {
	font-size: 14px;
	color: #FF0099;
}
-->
</style>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript">
function delrow(obj){
	var mytable=document.getElementById("mytable");
	//alert(obj.parentElement.innerHTML);
	//alert(obj.parentNode.innerHTML);
	//alert(obj.parentElement.parentElement.innerHTML);
	//alert(obj.parentElement.parentElement.id);
	//mytable.removeChild(obj.parentElement.parentElement);
	//mytable.removeNode(obj.parentNode.parentNode);
	//mytable.removeNode(obj.parentNode);
	for(i=0;i<mytable.rows.length;i++){
		//alert(mytable.rows[i].id);
		if(mytable.rows[i].id==obj.parentElement.parentElement.id){
			mytable.deleteRow(i);
		}
	}
}
function formSubMit(){
	var myform=document.getElementById("myform");
	var aSelects = document.body.getElementsByTagName("select");
	//alert('size='+aSelects.length);
	//将所有的select全部选中
	for(i=0;i<aSelects.length;i++){
		for(j=0;j<aSelects[i].options.length;j++){
			aSelects[i].options[j].selected=true;
		}
	}
	myform.submit();
}
function addvalue(obj,txt,slt){
	var otxt=document.getElementById(txt);
	var oslt=document.getElementById(slt);
	var oOption = document.createElement("option")
	oOption.value=otxt.value;
	oOption.text=otxt.value;
	oslt.options.add(oOption);
}
function removeItem(obj){
	obj.options.remove(obj.selectedIndex);
}
</script>
  </head>
  
  <body>
  <%
  String channel=request.getParameter("channel");
  if(channel==null || channel.equals("")){
  	channel="xml";
  }
  
  //method="post" enctype="multipart/form-data" 
  
  StringBuffer sb=new StringBuffer();
  StringBuffer sb1=new StringBuffer();
  String action=request.getParameter("action");
    	if(action!=null && !action.equals("")){
	    	Object obj=FrameworkConstant.hmAction.get(action);
	    	boolean blnStatus=false;
	    	if(obj!=null){
	    		ActionBean ab = (ActionBean)obj;
	    		
		    	List list=ab.getActionContextData();
	    		for(int i=0;i<list.size();i++){
	    			ActionContextDataBean acdb=(ActionContextDataBean)list.get(i);
	    			String name=acdb.getName();
	    			String type=acdb.getType();
	    			String comment=acdb.getComment();
	    			ArrayList rules=acdb.getRules();
	    			String sRules="<span class='aaa'>验证:";
	    			for(int j=0;j<rules.size();j++){
	    				RulesPO rpo=(RulesPO)rules.get(j);
	    				String sTmp=rpo.toString();
	    				int k=sTmp.indexOf(":[]");
	    				if(k==-1){
	    					sRules+=sTmp;
	    				}else{
	    					sRules+=sTmp.substring(0,k);
	    				}
	    				if(j!=rules.size()-1){
	    					sRules+=",";
	    				}
	    			}
	    			sRules+="</span>";
	    			String sTmp="";//用于控制是显示哪种的表单域
					if(acdb.isOutput()){
						sTmp="<input type=\"text\" name=\""+name+"\" value=\"此为输出参数,不可输入\" size=\"60\" readonly=\"readonly\"/>";
					}else{
						if(type.equals("array")){
							sTmp="<input type=\"text\" name=\"xx"+name+"\" id=\"xx"+name+"\" size=\"10\"/>"
							+"<input type=\"button\" value=\"add\" onclick=\"addvalue(this,'xx"+name+"','"+name+"')\"/>"
							+"<select name=\""+name+"\" id=\""+name+"\" name=\""+name+"\" multiple=\"multiple\" size=\"3\" ondblclick=\"removeItem(this)\">";
						}else{
							if(type.equals("file")){
								sTmp="<input type=\"file\" name=\""+name+"\" id=\""+name+"\" size=\"60\"/>";
								blnStatus=true;
							}else{
								sTmp="<input type=\"text\" name=\""+name+"\" id=\""+name+"\" size=\"60\"/>";
							}
						}
					}
  					sb1.append("<tr id=\"tr"+i+"\">").append("\r\n");
  					sb1.append("<td width=\"165\">").append(name).append(":").append(type).append("<br/>").append(comment==null?"":comment).append("<br/>").append(sRules).append("</td>").append("\r\n");
  					sb1.append("<td width=\"382\">").append(sTmp).append("\r\n");
  					sb1.append("<td width=\"165\"><input type=\"button\" onclick=\"delrow(this)\" value=\"删除参数\"/></td>").append("\r\n");
  					sb1.append("</tr>").append("\r\n");
  					
  					//图片验证码
		    		if(i==list.size()-1){
		    			sb1.append("<tr id=\"tr"+i+"\">").append("\r\n");
	  					sb1.append("<td colspan=\"3\">").append("<img src=\"validateCode.jsp\"/>").append("</td>").append("\r\n");
	  					sb1.append("</tr>").append("\r\n");
		    		}
    		}
    		String f="";
    		if(blnStatus){
    			f="<form id=\"myform\" action=\""+channel+"\" method=\"post\" enctype=\"multipart/form-data\"  target=\"_blank\">";
    			
    		}else{
    			  //method="post" enctype="multipart/form-data" 
    			f="<form id=\"myform\" action=\""+channel+"\" method=\"get\" target=\"_blank\">";
    		}
    		sb.append(f).append("\r\n");
    		sb.append("<p><input type=\"button\" onclick=\"formSubMit()\" value=\"提交\"/></p>").append("\r\n");
    		sb.append("<table id=\"mytable\" width=\"560\" border=\"1\" align=\"left\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#97BBF0\">").append("\r\n");
    		sb.append("<tr>").append("\r\n");
    		sb.append("<td width=\"165\">action:</td>").append("\r\n");
    		sb.append("<td width=\"382\"><input type=\"text\" name=\"action\" id=\"action\" value=\"").append(ab.getActionid()).append("\" size=\"60\"/></td>").append("\r\n");
    		sb.append("<td width=\"165\">&nbsp;").append("\r\n");
    		sb.append(sb1);
    		sb.append("</tr>").append("\r\n");
    		sb.append("</table>").append("\r\n");
    		sb.append("</form>").append("\r\n");
    		
    	}
    	out.println(sb.toString());
}
    	  %>
    	  
  </body>
</html>
